package com.daikun.common.aop.handler;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.stereotype.Component;

import java.lang.reflect.Method;

/**
 *
 * @author earl created 2025-07-09
 * @version init 0.0.1
 */
@Slf4j
@Aspect
@Component
public class BaseEventHandler {

    @Pointcut("@annotation(com.daikun.common.aop.annos.BaseEvent)")
    public void invoke() {}

    @Around("invoke()")
    public Object before(ProceedingJoinPoint point) {
        MethodSignature target = (MethodSignature) point.getSignature();
        Method method = target.getMethod();

        try {
            return point.proceed();
        } catch (Throwable e) {
            log.info("WholeProcessEventParser.before 接口请求异常 -> {}", e.getMessage(), e);
            throw new RuntimeException(e);
        }
    }

}
